package com.yonyou.gmcc.gateway.web.controller.authorization;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;


@Controller
public class TestController {
    @Autowired
	private ApplicationContext applicationContext;

	@RequestMapping(value="/comp/cpx", method=RequestMethod.GET, consumes="application/json")
	public @ResponseBody String login(HttpServletRequest request, RedirectAttributes rediect) {
		RibbonLoadBalancerClient r1=(RibbonLoadBalancerClient)this.applicationContext.getBean("loadBalancerClient");
    	ServiceInstance i=r1.choose("service-points");
    	System.out.println("host"+i.getHost());
		return "cpx.success";
	}
	@RequestMapping(value="/user/edit/test", method=RequestMethod.GET, consumes="application/json")
	public @ResponseBody String userTest(HttpServletRequest request, RedirectAttributes rediect) {
		return "userTest.success";
	}
}
